--诛伏赐死
local zhufucisi = fk.CreateSkill {
    name = "mcdh_zhufucisi",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

zhufucisi:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        if player:usedSkillTimes(self.name, Player.HistoryRound) >= 2 then
            return false
        end
        for _, current in ipairs(player.room:getAlivePlayers()) do
            if current.phase == Player.Draw then return false end
        end
        local count = 0
        for _, move in ipairs(data) do
            if move.to == player.id and move.toArea == Card.PlayerHand then
                count = count + #move.moveInfo
                if count >= 2 then return true end
            end
        end
        return false
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player), function(current)
            return not current:isNude() or current:getMark("mcdh_ammo") > 0
        end)
        local to = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#mcdh_zhufucisi-invoke",
            skill_name = self.name,
            cancelable = true
          })
          
        if #to > 0 then
            event:setCostData(self,to[1])
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self)
        local choices = {}
        if not to:isKongcheng() then
            table.insert(choices, "#mcdh_zhufucisi-discard")
        end
        if to:getMark("mcdh_ammo") > 0 then
            table.insert(choices, "#mcdh_zhufucisi-loseAmmo")
        end
        if #choices >= 0 then
            local choice = room:askForChoice(
                    player,
                    choices,
                    self.name,
                    "#mcdh_zhufucisi-choise::" .. to.id
            )
            if choice == "#mcdh_zhufucisi-discard" then
                room:askForDiscard(to, 1, 1, true, self.name, false, ".")
            elseif choice == "#mcdh_zhufucisi-loseAmmo" then
                lib.LoseAmmo(player, to, 1, self.name)
            end
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_zhufucisi"] = "诏罪",
    [":mcdh_zhufucisi"] = "『诛伏赐死』<br>每轮限两次，当你于摸牌阶段外一次性获得至少两张牌后，你可以令一名其他角色弃置一张牌、或令其失去1枚弹药。",
    ["#mcdh_zhufucisi-invoke"] = "诛伏赐死:选择一名角色，令其弃置一张牌或失去1枚弹药",
    ["#mcdh_zhufucisi-choise"] = "诛伏赐死:为 %dest 选择一项",
    ["#mcdh_zhufucisi-discard"] = "弃置一张牌",
    ["#mcdh_zhufucisi-loseAmmo"] = "退一枚弹药"
}

return zhufucisi